package com.sharer.last.handler;

import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 登录失败处理类
 *
 * @ClassName SecurityAuthenticationFailureHandler
 * @Author WangJin
 * @Date 2023/05/12/17:14
 * @Description 也可以直接实现AuthenticationFailureHandler
 * @Version 1.0
 */
@Slf4j
@Component
public class SecurityAuthenticationFailureHandler extends SimpleUrlAuthenticationFailureHandler {
    /**
     * <h3>登录失败自定义处理逻辑</h3>
     *
     * @param request
     * @param response
     * @param exception
     * @throws IOException
     * @throws ServletException
     */
    @Override
    public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {
        log.info("登录失败");
        // TODO 登录失败处理逻辑
        super.onAuthenticationFailure(request, response, exception);//使用默认登录失败逻辑
    }

}
